function [mag_image] = recon_multichannel_kspace(imgVolume, mrprot)
%DISPLAY_MULTICHANNEL_DATA Displays multi-channel raw MRI data loaded with rdMeas and reordered with reorder_raw_siemens_mridata.m 
%   Input : display_multichannel_data(imgVolume, mrprot)
%   Output: No Output - displays images from reorded raw siemens MRI data.
%
%
%
%   Author: Mahtieu Boudreau
%   Date: December 3nd 2013
%   Email: mathieu.boudreau2@mail.mcgill.ca
%   Last updated: December 3nd 2013


% Get number of slices
if length(size(imgVolume)) == 4
    numSlices = size(imgVolume,length(size(imgVolume))-2);
elseif length(size(imgVolume)) == 3
    numSlices = 1;
else
    disp('Error, can only handle input files that have 4 dimensions (3D) or 3 dimensions (single slice).')
end

numChannels = size(imgVolume,length(size(imgVolume)));

% If demanded, FFT the data before displaying it
    
     % 3D or Multi-Slice
     if length(size(imgVolume)) == 4
         
         % 3D 
         if(strcmp(mrprot.tMRAcquisitionType,'3D'))
             for chIndex = 1:numChannels
                 imgVolume(:,:,:,chIndex) = ifftshift(ifftn(imgVolume(:,:,:,chIndex)));
             end
          
         % Multi-Slice
         elseif(strcmp(mrprot.tMRAcquisitionType,'2D'))
             for chIndex = 1:numChannels
                 for slIndex = 1:numSlices
                    imgVolume(:,:,slIndex,chIndex) = ifftshift(ifftn(imgVolume(:,:,slIndex,chIndex)));
                 end
             end
         end
         
     % Single slice    
     else
         for chIndex = 1:numChannels
             imgVolume(:,:,chIndex) = ifftshift(ifftn(imgVolume(:,:,chIndex)));
         end
     end



for ii = 1:numChannels
    if length(size(imgVolume)) == 4    
        if ii == 1
            sumsqrImage=abs(imgVolume(:,:,:,ii)).^2;
        else
            sumsqrImage=sumsqrImage+abs(imgVolume(:,:,:,ii)).^2; % Sum of squares of the *complex* data.
        end
    else
        if ii == 1
            sumsqrImage=abs(imgVolume(:,:,ii)).^2;
        else
            sumsqrImage=sumsqrImage+abs(imgVolume(:,:,ii)).^2; % Sum of squares of the *complex* data.
        end        
    end
end
        
mag_image=fliplr(imrotate(abs(sqrt(sumsqrImage)),180));

end

